<?php 
if(isset($_GET['action'])){
  
  if($_GET['action']=='save'){
    
    require_once('Config.php');
    
    $title = $_POST['title'];
    $outline = $_POST['outline'];
    $content = $_POST['content'];
    $createdTime =  date("Y-m-d H:i:s");

    
    $sql = "insert into news values(null,'".$title."','twilight','twilight','".$outline."','".$content."','".$createdTime."','".$createdTime."',0)";
   
    if(mysql_query($sql)){
     $sessionMessage ="Save content success!";
     }else{
       
        $sessionMessage = 'Save conent failure!';
     
        }
     $messageFlag='1';
  
    
    
  }
  
}


?>

<html>
  <head>
    <title>
      Add news !
    </title>
    <link href="css/admin-common.css" rel="stylesheet" type="text/css">
 <link type="text/css" href="css/ui-lightness/jquery-ui-1.7.3.custom.css" rel="stylesheet" /> 
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="js/common.js">
    </script>
  </head>
  <body>
  <input type="hidden" name='messageFlag' id='messageFlag' value='<?php echo $messageFlag ?>'/>
    <h3>User Management : Add News</h3>
    <hr/>
    <p>
      <label>
        <Strong><a href="news.php">&lt; Back to NEWS LIST Page</a></Strong>
      </label>
    </p>
    <!--Here is the message from server when page load-->
    <div class="sessionMessage" style='display:none'>
    <?php echo $sessionMessage?>
    </div>
    <!--Session Message End-->

    <!--Add User Form-->
    <form action="?action=save" method="post" name="addNewsForm" id="addNewsForm">
      <label>
        <span>title</span>
        <input type="text" id="title" name="title" style="width:500px;"/>
      </label>
      <label>
        <span>outline:</span>
        <br/>
       
      <textarea cols="80" id="outline" name="outline" rows="10"><?php echo $aboutus_content ?></textarea>
      
    
      </label>
      <label>
        <span>content:</span>
       
      <textarea class="ckeditor" cols="80" id="content" name="content" rows="10"><?php echo $aboutus_content ?></textarea>
 
   
      </label>
     
      <p>
        <label>
          <span>&nbsp;</span>
       
       <button class="btn btn-style-1" type="button" onclick="return app.validInput()" ><b><b>Save</b></b></button> </label>
      </p>
    </form>
    <div id='validInputFailureDlg' title='Incomplete news info!'>
       <em><strong>News title</strong>,<em><strong>News outline</strong></em> and <em><strong>News content</strong> are required,Please fill them all!
    </div> 
    <div id='addNewsOkDlg' title="Confirmation" style='display:none'>
     You have just posted a news story,would you like to post more?
    </div>
    
  </body>
  <script type="text/javascript">
    var app={
      init: function() {
        $('#validInputFailureDlg').dialog({
          bgiframe: true,
          modal: true,
          draggable:false,
          autoOpen:false,
          width:300,

          buttons: {
            Ok: function() {
              $(this).dialog('close');
            }

          }
        });
        $('#addNewsOkDlg').dialog({
          bgiframe: true,
          modal: true,
          draggable:false,
          autoOpen:false,
          width:300,

          buttons: {
            'Yes,I want to': function() {
               document.location.replace('news_addForm.php');
                $(this).dialog('close');
            },

            'No,go back to news list': function() {
             document.location.replace('news.php');
            }

          }
        });
        
        if($('#messageFlag').val()=='1'){
          
           $('#addNewsOkDlg').dialog('open');
          }
      },

      validInput: function() {
        var contentObj =CKEDITOR.instances.content;

        if(jQuery.trim($('#title').val())=="" || jQuery.trim($('#outline').val())=="" || jQuery.trim(contentObj.document.getBody().getHtml())=="") {

          $('#validInputFailureDlg').dialog('open');

          return false;
        }
        $('#addNewsForm').submit();
        return true;

      }

    }
  </script>
</html>
